package labelsystem.Service.Implements;/**
 * @projectName careOlder
 * @Description TODO
 * @author MCG
 * @time 2023/3/7 20:21
 */

import com.alibaba.fastjson2.JSONObject;
import com.zhenzi.sms.ZhenziSmsClient;
import labelsystem.Service.msgService;
import labelsystem.utils.RandomUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 *description: TODO
 *@author MCG
 *@date 2023/3/7 20:21
 *@Version 1.0
 */
@Service
public class msgServiceImplement implements msgService {
    String apiUrl="http://sms_developer.zhenzikj.com";
    String appId="112903";
    String appScret="3183ef5b-5c9a-4d65-b83c-ddbf3ced8ac3";
    @Override
    public boolean sendMsg(String phone,String code,int type){
        boolean flag=false;
        //发送短信
        ZhenziSmsClient zhenziSmsClient=new ZhenziSmsClient(this.apiUrl,this.appId,this.appScret);
        //生成四位数的验证码
        //client.send(mobile, "您的验证码为:" + verifyCode + "，该码有效期为5分钟，该码只能使用一次!");
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("number", phone);
            if(type==1){
                params.put("templateId", "11264");
            }else{
                params.put("templateId","11391");
            }
            //这个参数就是短信模板上那两个参数
            String[] templateParams = new String[2];
            templateParams[0] = code;
            templateParams[1] = "5分钟";
            params.put("templateParams", templateParams);
            String result = zhenziSmsClient.send(params);
            System.out.println(result);
        } catch (Exception e){
            e.printStackTrace();
        }
        flag=true;
        return flag;
    }

    @Override
    public boolean sendAttentionMSG(Long phone, String messageType) {
        boolean flag=false;
        //发送短信
        ZhenziSmsClient zhenziSmsClient=new ZhenziSmsClient(apiUrl,appId,appScret);
        //生成四位数的验证码
        //client.send(mobile, "您的验证码为:" + verifyCode + "，该码有效期为5分钟，该码只能使用一次!");
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("number", phone);
            params.put("templateId", messageType);
            //这个参数就是短信模板上那两个参数
            String result = zhenziSmsClient.send(params);
            System.out.println(result);
        } catch (Exception e){
            e.printStackTrace();
        }
        flag=true;
        return flag;
    }
}
